import React, { PureComponent } from 'react';
import { message, Form } from 'antd';
import { connect } from 'dva';
import SyOrderTableComponent from '../../components/SyOrderTableComponent';
import moment from 'moment';

const FormItem = Form.Item;
@Form.create()
@connect(state => ({
  modelState: state.systemOrganization,
}))
export default class SystemOrganization extends SyOrderTableComponent {

  _initSortion = { sortField: 'id', sortOrder: 'desc', };
  _initPagination = { pageSize: 10, current: 1, };
  _initCriteriaQuery = {};
  _operator = [];

  initSelection() {
    const { dispatch } = this.props;
    dispatch({
      type: 'systemOrganization/fetchSelectItems',
      payload: { service: '/user', apiUrl: '/system/organization', selectName: 'systemOrganizationSelectItems' }
    });
  }

  operator = [
  ];

  componentWillMount() {
    this.initSelection();
    this.setState({
      baseModel: 'systemOrganization',
      needTableColumnsOperator: true,
      tableBorder: true,
      operator: this.operator,
      needAdd: true,
      needEdit: true,
      needDelete: true,
      needSearch: true,
      needTableCheckbox: true,
      tableScroll: { y: 800 },
      tableColumns: [
        {
          title: '部门名称',
          dataIndex: 'organizationName',
          width: 200,
        },
        // {
        //   title: '别名',
        //   dataIndex: 'alias',
        //   width: 180,
        // },
        {
          title: '上级部门',
          dataIndex: 'superOrganization.organizationName',
          width: 200,
        },
        {
          title: '备注',
          dataIndex: 'remark',
          width: 240,
          type: 'longString'
        },
        {
          title: '创建人',
          dataIndex: 'createUser.name',
          width: 160,
        },
        {
          title: '创建时间',
          dataIndex: 'createTime',
          // width: 200,
        },
      ],
      searchFormItem: [
        {
          name: 'organizationName',
          label: '部门名称',
          placeholder: '部门名称',
          type: 'string',
        },
        // {
        //   name: 'alias',
        //   label: '别名',
        //   placeholder: '部门名称',
        //   type: 'string',
        // },
        {
          name: 'superOrganization',
          label: '上级部门',
          placeholder: '上级部门',
          type: 'select',
          selectOption: { itemName: 'systemOrganizationSelectItems', name: 'organizationName', value: 'id', },
        },
      ],
      simpleAddFormItem: [
        {
          name: 'organizationName',
          label: '部门名称',
          placeholder: '部门名称',
          type: 'string',
          rules: [{
            required: true, message: '请输入部门名称',
          }],
        },
        // {
        //   name: 'alias',
        //   label: '别名',
        //   placeholder: '别名',
        //   type: 'string',
        //   rules: [{
        //     required: true, message: '请输入别名',
        //   }],
        // },
        {
          name: 'superOrganizationId',
          label: '上级部门',
          placeholder: '上级部门',
          type: 'select',
          selectOption: { itemName: 'systemOrganizationSelectItems', name: 'organizationName', value: "id" },
        },
        {
          name: 'remark',
          label: '备注',
          placeholder: '备注',
          type: 'longString',
          selectOption: [{ name: '', value: '' }],
        },
      ],
      simpleEditFormItem: [
        {
          name: 'organizationName',
          label: '部门名称',
          placeholder: '部门名称',
          type: 'string',
          rules: [{
            required: true, message: '请输入部门名称',
          }],
        },
        // {
        //   name: 'alias',
        //   label: '别名',
        //   placeholder: '别名',
        //   type: 'string',
        //   rules: [{
        //     required: true, message: '请输入别名',
        //   }],
        // },
        {
          name: 'superOrganizationId',
          label: '上级部门',
          placeholder: '上级部门',
          type: 'select',
          selectOption: { itemName: 'systemOrganizationSelectItems', name: 'organizationName', value: "id" },
        },
        {
          name: 'remark',
          label: '备注',
          placeholder: '备注',
          type: 'longString',
          selectOption: [{ name: '', value: '' }],
        },
      ],
    });
  }

  constructor(props) {
    super(props);
  }

  componentDidMount() {
    super.componentDidMount();
  }
}
